<template>
  <view class="selected-page">
    <!-- 顶部背景图 -->
    <image src="/static/common/weipinhui/sale.png" mode="scaleToFill" />
    <!-- 顶部文案 -->
    <view class="top-content">
      <view class="title-text">大牌寻宝</view>
      <image src="/static/common/weipinhui/miaosha.png" mode="widthFix" />
      <text class="iconfont icon-weibiaoti--40"></text>
    </view>

    <scroll-view
      class="menu-content"
      scroll-y="true"
      @scroll="scrollFn"
      :show-scrollbar="false"
    >
      <!-- 自定义banner -->
      <booth005></booth005>
      <view class="list-box">
        <view
          class="top-fixed"
          :class="{ fixedStyle }"
          :style="{ top: setFixedTop + 'px' }"
        >
          <topNav003></topNav003>
        </view>
        <view class="panel-list-item">
          <!-- 动态每个面板组件 -->
          <panel006
            class="list-item"
            :showData="itemData"
            v-for="itemData in weipinhuiBigData"
            :key="itemData.id"
          >
          </panel006>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import {
  defineComponent,
  reactive,
  toRefs,
  onMounted,
  getCurrentInstance,
} from "vue";
import { weipinhuiBigData } from "@/common/simulatedData.js";

export default defineComponent({
  name: "",
  props: {},
  components: {},
  setup() {
    const data = reactive({
      weipinhuiBigData,
      fixedStyle: false,
      scrollTop: 0,
      actualScrollTop: 0,
      setFixedTop: 0,
    });
    onMounted(() => {
      getScrollInfo();
      getTopFixedInfo();
    });
    // 获取滚动元素位置信息
    const { proxy } = getCurrentInstance();
    // 获取顶部tabs滚动元素信息
    const getScrollInfo = () => {
      const query = uni.createSelectorQuery().in(proxy);
      query
        .select(".uni-scroll-view-content")
        .boundingClientRect((ele) => {
          data.scrollTop = ele.top;
        })
        .exec();
    };
    const getTopFixedInfo = () => {
      const query = uni.createSelectorQuery().in(proxy);
      query
        .select(".top-fixed")
        .boundingClientRect((ele) => {
          data.actualScrollTop = ele.top - data.scrollTop;
        })
        .exec();
    };

    const scrollFn = (e) => {
      if (e.detail.scrollTop >= data.actualScrollTop) {
        data.fixedStyle = true;
        data.setFixedTop = data.scrollTop;
      } else {
        data.fixedStyle = false;
        data.setFixedTop = 0;
      }
    };
    return {
      scrollFn,
      ...toRefs(data),
    };
  },
});
</script>

<style scoped lang="less">
.selected-page {
  position: relative;
  height: 100vh;
  width: 100%;
  //   渐变
  background: #eb0b34;
  padding-top: 80rpx;
  box-sizing: border-box;
  image {
    width: 80%;
    height: 600rpx;
    position: absolute;
    left: 50%;
    transform: translateX(-50%) rotate(10deg);
    top: -230rpx;
  }
  .top-content {
    position: relative;
    z-index: 1;
    height: 53rpx;
    .title-text {
      position: absolute;
      left: -16rpx;
      font-size: 60rpx;
      color: #fff;
      font-weight: 700;
      // 倾斜
      transform: skewX(-15deg);
    }
    image {
      position: absolute;
      left: 210rpx;
      top: 10rpx;
      width: 100rpx;
      // 旋转
      transform: rotate(-30deg);
    }
    .icon-weibiaoti--40 {
      position: absolute;
      right: 20rpx;
      font-size: 38rpx;
      top: 6rpx;
    }
  }
  .menu-content {
    height: calc(100vh - 232rpx);
    box-sizing: border-box;
    overflow: hidden;
    position: absolute;
    border-radius: 35rpx 35rpx 0 0;

    .list-box {
      padding-bottom: 0rpx;
      background: #f5f5f5;
      padding-top: 86rpx;
      border-radius: 35rpx 35rpx 0 0;
      position: relative;
      .top-fixed {
        border-radius: 35rpx 35rpx 0 0;
        overflow: hidden;
        background: #f5f5f5;
        z-index: 90;
        width: 100%;
        box-sizing: border-box;
        position: absolute;
        top: 0rpx;
        left: 0rpx;
        &.fixedStyle {
          position: fixed;
        }
      }
      .panel-list-item {
        width: 100%;
        column-count: 2;
        column-gap: 20rpx;
        row-gap: 0rpx;

        // 行间距
        padding: 0 10rpx;
        box-sizing: border-box;
        .list-item {
          margin-bottom: 20rpx;
        }
      }
    }
  }
}
</style>
